
<!DOCTYPE html>
<html xmlns:th="http://www.w3.org/1999/xhtml">
<head>
    <title>业务维护</title>
    <meta charset="UTF-8">
    <link href="/static/devtools30/layui/css/layui.css" rel="stylesheet" />
    <link href="/static/devtools30/css/devindexbase.css" rel="stylesheet" />
    <script src="/static/devtools30/js/jquery-1.11.2.min.js" type="text/javascript"></script>
    <script src="/static/devtools30/layui/layui.all.js" type="text/javascript"></script>
    <script src="/static/devtools30/js/devtoolCommon.js" type="text/javascript"></script>
<style>
    body {
        background: #F7F7F7;
    }


    /*顶部容器*/

    .tophead {
        height: 32px;
        line-height: 32px;
        border: 1px solid #F7F7F7;
        padding: 0 5px;
        margin: 0 2px;
    }

    .tophead .layui-form-item {
        margin-bottom: 0px!important;
    }

    .tophead .layui-form-label {
        padding: 0;
        line-height: 25px;
        width: auto;
    }

    .tophead .layui-input-block {
        margin-left: 32px;
    }

    .tophead .layui-input,
    .layui-select {
        height: 25px;
    }

    .tophead .layui-form-select dl {
        top: 26px;
        padding: 0;
    }

    .tophead .layui-form-select dl dd,
    .layui-form-select dl dt {
        line-height: 24px;
    }

    .tophead .layui-form-item {
        width: 165px;
    }

    .tophead .layui-form-select .layui-edge {
        border-width: 4px;
    }

    .tophead .search .layui-input-block {
        margin-left: 32px;
    }

    .tophead .layui-input-block {
        min-height: 26px;
    }


    /*按钮组边框*/

    .layui-btn-group .layui-btn-primary:first-child {
        border-left: 1px solid #c9c9c9!important;
    }

    .layui-btn-group .layui-btn {
        border-left: 1px solid rgba(255, 255, 255, .5)!important;
    }


    /*按钮大小*/

    .layui-btn {
        height: 26px;
        line-height: 26px;
        font-size: 11px;
    }


    /*table*/

    .layui-table,
    .layui-table-view {
        margin: 0;
    }

    .layui-table td,
    .layui-table th {
        font-size: 11px!important;
    }
</style>

</head>
<body>
<div>
    <!--头部-->
    <div class="flex flex-align-center flex-jusity-betreen tophead backgroundf">
        <div class="flex flex-align-center">
            <div class="layui-form flex flex-align-center">
                <div class="layui-form-item">
                    <label class="layui-form-label">分类</label>
                    <div class="layui-input-block">
                        <select name="selType" id="selType" lay-filter="selType">

                        </select>
                    </div>
                </div>
                <div class="layui-form-item marginleft10 search">
                    <label class="layui-form-label">查询</label>
                    <div class="layui-input-block">
                        <input type="text" id="searchValue" name="searchValue" placeholder="请输入代码/名称" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <button type="button" class="layui-btn layui-btn-sm layui-btn-normal marginleft10" onclick="loadData()">确定</button>
            </div>
        </div>
        <div class="layui-btn-group btnwrap">
            <button type="button" class="layui-btn layui-btn-primary layui-btn-sm" name='add'>新增</button>
            <button type="button" class="layui-btn layui-btn-primary layui-btn-sm" name='edit'>修改</button>
            <button type="button" class="layui-btn layui-btn-primary layui-btn-sm" name='del'>删除</button>
        </div>
    </div>
    <!--表格-->
    <div style="padding: 2px;width: 100%;background: #F7F7F7;">
        <div class="backgroundf">
            <table id="mygrid" lay-filter="mygrid"></table>
        </div>
    </div>
</div>
</body>
<script>

    var height = dlCommon.getWinHeight();
    var width=dlCommon.getWinWidth();
    var selTableId="";
    $(function() {


        initGrid();

        initEvent();

        bindForm();

        loadData();

    })
    //数据表
    function loadData(){

        var data={
            condition:$("#searchValue").val(),
            flid:$("#selType").val()
        };
        layui.table.reload("mygrid",{
            url:"/DevtApiMainEntityController/getAll",
            where:data,
            loading:true,
            page: false
        });

    }


    function bindForm(){
        dlCommon.getJSON("/DevtApiTypeController/getAll",{},function(res){
            var str='<option value="">全部</option>';
            $(res.data).each(function(i,d){
                str+='<option value="'+d.id+'">'+d.mc+'</option>';
            })
            $("#selType").html(str);
            layui.form.render();
        });

    }
    //初始化grid
    function initGrid(){
        //第一个实例
        layui.table.render({
            elem: '#mygrid'
            ,height: 419
            ,height: height-50
            ,size: 'sm' //小尺寸的表格
            ,page: false //开启分页
            ,cols: [
            [ //表头
                {field: 'xh', title: '排序', width:'8%', fixed: 'left', sort: true}
                ,{field: 'flmc', title: '分类名', width:'15%'}
                ,{field: 'mc', title: '业务名', width:'24%',}
                ,{field: 'dm', title: '业务代码', width:'20%'}
                ,{field: 'bz', title: '备注'}
            ]]
        });


    }
    //初始化事件
    function initEvent(){
        /*增删改点击方法*/
        $('.btnwrap>button').on('click',function(){
            var names = $(this)[0].name;
            //新增
            if(names == 'add'){
                dlCommon.layeropen(500,300,"新增",'/DevtApiMainEntityController/edit');
                return;
            }
            if(!selTableId){
                dlCommon.layerInfo('请选择数据');
                return;
            }
            //修改
            if(names == 'edit'){
                dlCommon.layeropen(500,300,"修改",'/DevtApiMainEntityController/edit?id='+selTableId);

            }
            if(names == 'del'){
                //删除
                del(selTableId);
            }
        })


        //单击表格
        dlCommon.layerTableOn('mygrid', function(obj){
            selTableId=obj.data.id;
        });
    }
    function del(id) {
        if(!id){
            return;
        }
        dlCommon.layerConfirm("是否确定删除该业务？",function(){
            dlCommon.getJSON("/DevtApiMainEntityController/delete",{id:id},function(res){
                if(!res.success){
                    dlCommon.layerError(res.msg);
                    return;
                }
                loadData();
            })
        })

    }
</script>
</html>
